package com.isp.gateway.web.reference;

import com.isp.aut.api.client.IAuthClient;
import com.isp.common.model.user.PermissionDTO;
import com.isp.common.model.vo.Result;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * @author linsy
 * @version 1.0
 * @created 2024/3/12 11:12
 */
@Slf4j
@Component
public class IAuthReference {


    @DubboReference
    private IAuthClient iAuthClient;

    public boolean ignoreAuthentication(String url) {
        return iAuthClient.ignoreAuthentication(url);
    }

    public Jws<Claims> getJwt(String authentication) {
        return iAuthClient.getJwt(authentication);
    }

    /**
     * 数据权限验证
     *
     * @param authentication 身份验证
     * @param permissionDTO  许可dto
     * @param groupCode      组织代码
     * @return {@link Result}
     */
    public Result dataAuthenticate(String authentication, String groupCode, PermissionDTO permissionDTO) {
        return iAuthClient.dataAuthenticate(authentication, groupCode, permissionDTO);
    }

    /**
     * 调用签权服务，判断用户是否有权限
     *
     * @param authentication
     * @param url
     * @param method
     * @return Result
     */
    public Result authenticate(String authentication, String url, String method) {
        return iAuthClient.authenticate(authentication, url, method);
    }

    /**
     * 查看签权服务器返回结果，有权限返回true
     *
     * @param authResult
     * @return
     */
    public boolean hasPermission(Result authResult) {
        return iAuthClient.hasPermission(authResult);
    }

    /**
     * 调用签权服务，判断用户是否有权限
     *
     * @param authentication
     * @param url
     * @param method
     * @return true/false
     */
    public boolean hasPermission(String authentication, String url, String method) {
        return iAuthClient.hasPermission(authentication, url, method);
    }

    /**
     * 是否无效authentication
     *
     * @param authentication
     * @return
     */
    public boolean invalidJwtAccessToken(String authentication) {
        return iAuthClient.invalidJwtAccessToken(authentication);
    }

}
